<?php


namespace app\controller;


use app\repository\Device\DeviceRepository;
use support\Request;

class DeviceController extends BaseController
{

    protected $repository;


    public function __construct(DeviceRepository $repository)
    {
        $this->repository = $repository;
    }

    public function udp_scan(Request $request)
    {
        $all = $request->all();
        $data['code'] = $request->input("code");
        $data['ip'] = $request->input("ip");
        $data["device_num"] = $request->input("deviceNum");
        dump($all);
        $res = $this->repository->handleUdpScan($data);
        return $this->res($res);
    }

    public function begin_action(Request $request)
    {
        $key = $request->input("key");
        $cardNo = $request->input("card_no");
        $action = $request->input("action");
        $handle_begin_action = $this->repository->handleBeginAction($key,$cardNo,$action);
        return $this->res($handle_begin_action);
    }

    public function use_action()
    {

    }

    public function use_score(Request $request)
    {
        $data['card_no'] = $request->input("card_no");
        $data['city_no'] = $request->input("city_no");
        $data['vene_no'] = $request->input("vene_no");
        $data['site_no'] = $request->input("site_no");
        $data['score'] = $request->input("score");
        $data['type_no'] = $request->input("type_no");
        $data['project_no'] = $request->input("project_no");
        $data['project_level'] = $request->input("project_level");
        $data['is_promotion'] = $request->input("is_promotion");
        $data['time'] = $request->input("time");
        $data['life'] = $request->input("life");
        $data['timestamp'] = $request->input("timestamp");
        $use_score = $this->repository->use_score($data);
        return $this->res($use_score);
    }

    public function check_key(Request $request)
    {
        $key = $request->input("key");
        $type = $request->input("type","game");
        if (!$key){
            return $this->error("");
        }
        $check_key = $this->repository->check_key($key,$type);
        return $this->res($check_key);
    }
}